package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealMapper {
    /**
     * 根据分类统计套餐数
     *
     * @param id
     * @return
     */
    @Select("select count(*) from setmeal group by category_id having category_id = #{id}")
    Integer countByCateId(Long id);

    /**
     * 修改套餐信息
     *
     * @param setmeal
     */
    @AutoFill(OperationType.UPDATE)
    void updateSetmeal(Setmeal setmeal);

    /**
     * 新增套餐
     *
     * @param setmeal
     */
    @AutoFill(OperationType.INSERT)
    void insertSetmeal(Setmeal setmeal);

    /**
     * 分页查询
     *
     * @param pageQueryDTO
     * @return
     */
    Page<SetmealVO> pageQuery(SetmealPageQueryDTO pageQueryDTO);

    /**
     * 根据id查询套餐-批量版
     *
     * @param ids
     * @return
     */
    List<Setmeal> getByIds(List<Long> ids);

    /**
     * 批量删除套餐
     *
     * @param id
     */
    @Delete("delete from setmeal where id = #{id}")
    void deleteById(Long id);

    /**
     * 查询套餐信息
     * @param id
     * @return
     */
    Setmeal getById(Long id);

    /**
     * 根据分类id查询套餐
     *
     * @param categoryId
     * @return
     */
    @Select("select * from setmeal where category_id = #{categoryId} order by create_time desc;")
    List<Setmeal> list(Long categoryId);

    /**
     * 根据套餐id查询包含的菜品
     *
     * @param id
     * @return
     */
    List<DishItemVO> getSetmealDishes(Long id);
}
